package com.umeox.watch.moto.launcher.service;


import android.app.IntentService;
import android.content.Intent;

import androidx.annotation.Nullable;

import com.umeox.moto.watch.themes.AppJob;
import com.umeox.moto.watch.themes.skin.loader.ResourceManager;
import com.umeox.watch.moto.dataservice.DataProvider;
import com.umeox.watch.moto.launcher.bean.NotificationBean;
import com.umeox.watch.moto.launcher.utils.MessageUtil;
import com.umeox.watch.moto.launcher.utils.SkinUtil;

import org.greenrobot.eventbus.EventBus;

public class AppJobService extends IntentService {
    private static final String ACTION_MISS_CALL = "com.wherecom.intent.action.MISS_CALL";
    public AppJobService() {
        super("AppJobService");
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        if (intent == null) {
            return;
        }
        final int jobType = intent.getIntExtra(AppJob.EXTRA_JOB_TYPE, 0);
        switch (jobType) {
            case AppJob.JOB_TYPE_MISSED_CALL:
                setupMissedCall();
                break;
            case AppJob.JOB_TYPE_SKIN_LOAD:
                SkinUtil.loadSkinResources(getApplicationContext());
//                SkinUtil.loadMp3Resources(getApplicationContext());
                ResourceManager.getInstance().load(DataProvider.getCurrentTheme());
                break;
            default:
                break;
        }

    }

    private void setupMissedCall() {
        final NotificationBean missedCallBean = MessageUtil.getMissedCallBean(getApplicationContext(), DataProvider.isRefusePhone());
        if (missedCallBean != null) {
            final Intent intent = new Intent(ACTION_MISS_CALL);
            intent.putExtra("phone_number",missedCallBean.getId());
            sendBroadcast(intent);
            EventBus.getDefault().post(missedCallBean);
        }
    }
}
